package cn.xinzhi.servlet;

import cn.xinzhi.Util.KeyDaoUtil;
import cn.xinzhi.dao.Impl.Yh_loginDaoImpl;
import cn.xinzhi.entity.Yh_login;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.List;

/**
 * 注册
 */
@WebServlet(name = "LoginServlet")
public class LoginServlet extends HttpServlet   {
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        response.setContentType("text/html;charset=utf-8");
        request.setCharacterEncoding("utf-8");
        PrintWriter out = response.getWriter();
        String user=request.getParameter("username");
        String pwd=request.getParameter("password") ;
        //加密
        String pwdjm=new KeyDaoUtil(pwd).get32();

        String sjh=request.getParameter("numder");
        Yh_loginDaoImpl yh_loginDao=new Yh_loginDaoImpl();
        int conut = yh_loginDao.newLogin(user,pwdjm,sjh);
         if (conut!=0){
             response.sendRedirect(" login.jsp ");
         }else {
             response.sendRedirect("newlogin.jsp");
         }

        out.flush();
        out.close();

    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
         doPost(request,response);
    }
}
